#include<iostream>
#include<string>
#include<unordered_map>

using namespace std;

int main(){
	int n;
	string s; 
	unordered_map<char, int> map;
	cin >> s >> n;
	for (char c:s){
		map[c]++;
	}
	
	for (int i=0;i<n;i++){
		char c;
		cin >> c;
		cout<<map[c]<<endl;
	}
	return 0;
} 
